﻿@{
    ViewBag.Title = "集中排课";
    Layout = "~/Views/Shared/___newestMaster.cshtml";
}


@using ClassModel
@using ClassBLL

@{
    List<t_class_tearcher> teacherList = ViewBag.teacherList;
    int fileid = ViewBag.fileId;
    int userid = ViewBag.userId;
    t_teacher_centralize centralize = t_class_centralize_BLL.getSingleByFileId(fileid, userid);

    // 用户之前设置了集中排课数据。
    bool hasCentralize = centralize != null && !string.IsNullOrEmpty(centralize.tids);

    List<int> tids = new List<int>();
   
}


<div class="jzpk" style="">
    <div class="conConT">
        <ul>
            <li>我的任务：</li>
            <li>集中排课</li>
        </ul>
    </div>
    <div class="conConTo3 col-lg-12 col-md-12 col-sm-12">
        <ul>
            <li>集中排课</li>
            <li>
                <p>集中排课是指xxxxxxxxxxx</p>
                <p>默认情况下所有的老师都是集中排课</p>
            </li>
            <li class="allChoose">全选</li>
        </ul>
    </div>
    <div class="contenttext col-lg-12 col-md-12 col-sm-12">
        <ul>
            @if (teacherList != null)
            {
                if (centralize != null && !string.IsNullOrEmpty(centralize.tids))
                {
                    var stringList = centralize.tids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    for (int s = 0; s < stringList.Count; s++)
                    {
                        tids.Add(Convert.ToInt32(stringList[s]));
                    }
                }

                for (int t = 0; t < teacherList.Count; t++)
                {
                    t_class_tearcher current = teacherList[t];
                    string css = string.Empty;
                    if (tids.Count > 0)
                    {
                        if (tids.Contains(current.dataTxtid))
                        {
                            css = "actionsyes";
                        }
                    }
                    
                <li class="col-lg-2 col-md-4 col-sm-5 " data-teacherid="@(current.id)" data-datatxtid="@(current.dataTxtid)">@(current.teacher)<i class="@(css)"></i></li>    
                    
                }
            }
        </ul>
    </div>
    <input type="hidden" id="length" value="@((tids.Count == teacherList.Count) ? "true" : "false")"/>
    <input type="button" id="saveBtn" value="保存" />
    <input type="hidden" id="fileid" value="@(ViewBag.fileId)" />
    <input type="hidden" id="taskid" value="@(ViewBag.taskId)"/>
    <input type="hidden" id="hasCentralize" value="@(hasCentralize ? "1" : "0")" />
    <input type="hidden" id="allTeacherCount" value="@(teacherList.Count)"/>
</div>


@section script {
    <style type="text/css">
        .tipText {
            font-size: 18px !important;
        }
    </style>

    <script type="text/javascript">
        $(function () {
            var iList = $(".contenttext ul li i");
            // 用户事先没有设置集中排课数据，就默认全选。
            var hasCentralize = $("#hasCentralize").val();
            if (hasCentralize == "0") {
                // 全选按钮全选 

                $(".allChoose").addClass("actionsyes");
                iList.each(function (index, item) {
                    $(item).addClass("actionsyes");
                })
            }


            var $allSelected = $("#length").val();
            if ($allSelected == "true") {
                $(".allChoose").addClass("actionsyes");
            }


            // 全选
            $(".allChoose").on("click", function () {
                var $this = $(this);
                $this.toggleClass("actionsyes");
                if ($this.hasClass("actionsyes")) {
                    iList.each(function (index, item) {
                        $(item).addClass("actionsyes");
                    })
                } else {
                    iList.each(function (index, item) {
                        $(item).removeClass("actionsyes");
                    })
                }
            })


            var allTeacherCount = parseInt($("#allTeacherCount").val());
            // 单选
            $(".contenttext li").on("click", function () {
                $(this).find("i").toggleClass("actionsyes");
                if (!$(this).find("i").hasClass("actionsyes")) {
                    $(".allChoose").removeClass("actionsyes");
                } else {
                    var hasClassCount = 0;
                    $(".contenttext li i").each(function (index, item) {
                        if ($(item).hasClass("actionsyes")) {
                            hasClassCount++;
                        }
                    })

                    if (allTeacherCount == hasClassCount) {
                        $(".allChoose").addClass("actionsyes");
                    }
                }
            })


            $("#saveBtn").on("click", function () {
                // 获得用户选中的老师id数据
                var tids = '';
                $(".contenttext ul li").each(function (index, item) {
                    var $this = $(this);
                    if ($this.find("i").hasClass("actionsyes")) {
                        tids += $this.attr("data-datatxtid") + ",";
                    }
                })

                if (tids == '') return;

                /// 提交老师集中排课数据
                $.post("InsertCentralize", {
                    tids: tids,
                    fileid: $("#fileid").val(),
                    taskid: $("#taskid").val()
                }, function (data) {
                    if (data.status) {
                        showSuccess("集中排课数据保存成功!");
                    }
                })
            })
        })

    </script>
}